package ProjectViewer;

import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import ClassData.ClassData;
import ClassData.ClassDataList;

public class Panel_ClassList extends JScrollPane implements ListSelectionListener{

/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

JList myClassList;	
DefaultListModel mylistModel;
Panel_ClassData myDataPanel;

public Panel_ClassList (Panel_ClassData dataPanel)
{


	myDataPanel=dataPanel;

}





public void setClassList(ClassDataList listOfClasses)
{
	int counter;
	
	mylistModel = new DefaultListModel();
	

	
	for (counter=0;counter<listOfClasses.size();counter++)
		{
		mylistModel.addElement(listOfClasses.get(counter));
		}
	
	
	myClassList = new JList(mylistModel);
	myClassList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	myClassList.addListSelectionListener(this);
	
	getViewport().setView(myClassList);	
}






@Override
public void valueChanged(ListSelectionEvent arg0)
{
	int index;
	ClassData myClassData;
	

	index=myClassList.getSelectedIndex(); //.getFirstIndex();
	myClassData=(ClassData)mylistModel.get(index);
	
	myDataPanel.displayClass(myClassData);
	
}
	




}
